package com.lonton.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import com.lonton.service.MailService;
@Service
public class MailServiceImpl implements MailService{
	/**
	 * 发送简单邮件
	 * @param to 接受者
	 * @param subject 主题
	 * @param content 内容
	 */
	@Autowired
	private JavaMailSender mailSender;

	@Value("${mail.fromMail.addr}")
	private String from;
	@Override
	public void sendSimpleMail(String to, String subject, String content) {
		SimpleMailMessage mailMessage=new SimpleMailMessage();
		mailMessage.setFrom(from);
		mailMessage.setTo(to);
		mailMessage.setSubject(subject);
		mailMessage.setText(content);
		try {
			mailSender.send(mailMessage);
		}catch (Exception e){
			e.printStackTrace();
			System.out.println("发送简单邮件失败");
		}
	}
}
